/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.assertj.ohos.api.ability;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.ability.FormException;

import org.assertj.core.api.AbstractAssert;

import ohos.bundle.FormInfo;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;


/** AbilitySliceAssert */
public abstract class AbilitySliceAssert<S extends AbilitySliceAssert<S, A>, A extends AbilitySlice> extends AbstractAssert<S, A> {
    protected AbilitySliceAssert(A actual, Class<S> selfType) {
        super(actual, selfType);
    }

    /**
     * 原始设备标识
     *
     * @param deviceId 设备id
     * @return S
     */
    public S hasOriginalDeviceId(String deviceId) {
        isNotNull();
        int actualDeviceId = actual.getDisplayOrientation();
        assertThat(actualDeviceId)
                .overridingErrorMessage("Expected deviceId <%s> but was <%s>.", actualDeviceId, deviceId)
                .isEqualTo(deviceId);
        return myself;
    }

    /**
     * 具有表单
     *
     * @param formName 表单名称
     * @return S
     * @throws FormException
     */
    public S hasForm(String formName) throws FormException {
    isNotNull();
    List<FormInfo> infoList = actual.getAllForms();
    boolean contains = false;
    for(FormInfo info : infoList) {
        if(info.getFormName().equals(formName)) {
        contains = true;
        break;
        }
    }
    assertThat(contains).isTrue();
        return myself;
    }
}
